package com.ecut.property_project.controller;

import com.ecut.property_project.model.ApplicationForm;
import com.ecut.property_project.model.base.BaseCompany;
import com.ecut.property_project.model.base.BaseRegion;
import com.ecut.property_project.model.building.BuildingHead;
import com.ecut.property_project.model.project.ProjectHead;
import com.ecut.property_project.service.ApplicationFormService;
import com.ecut.property_project.service.base.BaseCompanyService;
import com.ecut.property_project.service.base.BaseRegionService;
import com.ecut.property_project.service.building.BuildingHeadService;
import com.ecut.property_project.service.bunk.BunkTenantService;
import com.ecut.property_project.service.project.ProjectDeptService;
import com.ecut.property_project.service.project.ProjectHeadService;
import com.ecut.property_project.service.project.ProjectPurposeService;
import com.ecut.property_project.service.room.RoomHeadService;
import com.ecut.property_project.utils.Page;
import com.ecut.property_project.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private ApplicationFormService applicationFormService;
    @Autowired
    private ProjectPurposeService projectPurposeService;
    @Autowired
    private ProjectDeptService projectDeptService;
    @Autowired
    private ProjectHeadService projectHeadService;

    @RequestMapping(value = "/getApplication")
    private Result getApplication(@RequestBody Map<String, String> data){
        ApplicationForm form = applicationFormService.selectByPrimaryKey(Integer.parseInt (data.get("id")));
        return Result.succ(200,"success",form);
    }
    @RequestMapping(value = "getProject")
    private Result getProject(@RequestBody Map<String, String> data){
        ProjectHead project = projectHeadService.selectByPrimaryKey(data.get("id"));
        project.setDeptList(projectDeptService.selectByHeadId(data.get("id")));
        project.setPurposeList(projectPurposeService.selectByHeadId(data.get("id")));
        return Result.succ(200,"success",project);
    }

    @Autowired
    private RoomHeadService roomHeadService;
    @RequestMapping(value = "getRoomCount")
    private Result getRoomCount(){
        int total = roomHeadService.getRoomCount();
        return Result.succ(200,"success",total);
    }

    @RequestMapping(value = "getTenantCount")
    private Result getTenantTotal(){
        int total = applicationFormService.getTenantCount();
        return Result.succ(200,"success",total);
    }

    @Autowired
    BaseCompanyService baseCompanyService;
    @RequestMapping(value = "getAllCompany")
    public Result getAllCompany(){
        List<BaseCompany> companyList= baseCompanyService.selectAll();
        return Result.succ(200,"success",companyList);
    }

    @Autowired
    BaseRegionService baseRegionService;
    @RequestMapping(value = "getRegionByPage")
    public Result getRegionByPage(@RequestBody Map<String, String> data){
        int pageSize = Integer.parseInt(data.get("pageSize"));
        int page = (Integer.parseInt(data.get("page")) - 1) * pageSize;
        int total = baseRegionService.getCount();
        List<BaseRegion> regions = baseRegionService.selectByPage(page,pageSize);

        Page<BaseRegion> pageObject = new Page<>(regions,total,pageSize,page);
        return Result.succ(200,"success",pageObject);
    }
    @Autowired
    BuildingHeadService buildingHeadService;
//    @RequestMapping(value = "getBuildingByRegion")
//    public Result getBuildingByRegion(@RequestBody Map<String, String> data){
//        String region = data.get("region");
//        String projectId = data.get("projectId");
//        List<BuildingHead> buildingHeads = buildingHeadService.selectBuildingByRegion(region, projectId);
//        return Result.succ(200,"success",buildingHeads);
//    }

//    @RequestMapping(value = "getRegionByProject")
//    public Result getRegionByProject(@RequestBody Map<String, String> data){
//        String projectId = data.get("projectId");
//        List<String> regions = buildingHeadService.selectAllRegionByProject(projectId);
//        return Result.succ(200,"success",regions);
//    }

    @Autowired
    BunkTenantService bunkTenantService;
    @RequestMapping(value = "getCountByYear")
    public Result getCountByYear(){
        List<Map<String,Integer>> yearToCount = bunkTenantService.getCountByYear();
        return Result.succ(200,"success",yearToCount);
    }
}
